//
//  TiDanDetailCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/9/11.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "TiDanDetailCell.h"

@interface TiDanDetailCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *NOTitleLab;
@property (nonatomic, strong) UILabel *NOLab;
@property (nonatomic, strong) UILabel *line1;
@property (nonatomic, strong) UIImageView *tiImgView;
@property (nonatomic, strong) UILabel *tiNameLab;
@property (nonatomic, strong) UILabel *tiAddressLab;
@property (nonatomic, strong) UILabel *tiCompanyLab;
@property (nonatomic, strong) UILabel *marginLine;
@property (nonatomic, strong) UIImageView *xieImgView;
@property (nonatomic, strong) UILabel *xieNameLab;
@property (nonatomic, strong) UILabel *xiePhoneLab;
@property (nonatomic, strong) UILabel *xieAddressLab;
@property (nonatomic, strong) UILabel *xieCompanyLab;
@property (nonatomic, strong) UILabel *line2;
@property (nonatomic, strong) UILabel *linkLine;
@property (nonatomic, strong) UIButton *listBtn;

@end

@implementation TiDanDetailCell

+ (instancetype)TiDanDetailCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"TiDanDetailCell";
    TiDanDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[TiDanDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        [self.contentView addSubview:self.bgView];
        
        self.NOTitleLab = [UILabel new];
        self.NOTitleLab.textColor = HexColor(0x9C9DB3);
        self.NOTitleLab.font = [UIFont systemFontOfSize:16];
        [self.bgView addSubview:self.NOTitleLab];
        
        self.NOLab = [UILabel new];
        self.NOLab.textColor = Color_ThemeColor;
        self.NOLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.NOLab];
        
        self.line1 = [UILabel new];
        self.line1.backgroundColor = Color_backgroundColor;
        [self.bgView addSubview:self.line1];
        
        self.tiImgView = [UIImageView new];
        self.tiImgView.image = [UIImage imageNamed:@"icon_add_ti"];
        [self.bgView addSubview:self.tiImgView];
        
        self.tiNameLab = [UILabel new];
        self.tiNameLab.textColor = HexColor(0x2B2C44);
        self.tiNameLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.tiNameLab];
        
        self.tiAddressLab = [UILabel new];
        self.tiAddressLab.textColor = HexColor(0x2B2C44);
        self.tiAddressLab.font = [UIFont systemFontOfSize:14];
        self.tiAddressLab.numberOfLines = 0;
        [self.bgView addSubview:self.tiAddressLab];
        
        self.tiCompanyLab = [UILabel new];
        self.tiCompanyLab.textColor = HexColor(0x2B2C44);
        self.tiCompanyLab.font = [UIFont systemFontOfSize:14];
        self.tiCompanyLab.numberOfLines = 0;
        [self.bgView addSubview:self.tiCompanyLab];
        
        self.marginLine = [UILabel new];
        self.marginLine.backgroundColor = Color_backgroundColor;
        [self.bgView addSubview:self.marginLine];
        
        self.xieImgView = [UIImageView new];
        self.xieImgView.image = [UIImage imageNamed:@"icon_add_xie"];
        [self.bgView addSubview:self.xieImgView];
        
        self.xieNameLab = [UILabel new];
        self.xieNameLab.textColor = HexColor(0x2B2C44);
        self.xieNameLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.xieNameLab];
        
        self.xiePhoneLab = [UILabel new];
        self.xiePhoneLab.textColor = Color_ThemeColor;
        self.xiePhoneLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.xiePhoneLab];
        
        self.xieAddressLab = [UILabel new];
        self.xieAddressLab.textColor = HexColor(0x2B2C44);
        self.xieAddressLab.font = [UIFont systemFontOfSize:14];
        self.xieAddressLab.numberOfLines = 0;
        [self.bgView addSubview:self.xieAddressLab];
        
        self.xieCompanyLab = [UILabel new];
        self.xieCompanyLab.textColor = HexColor(0x2B2C44);
        self.xieCompanyLab.font = [UIFont systemFontOfSize:14];
        self.xieCompanyLab.numberOfLines = 0;
        [self.bgView addSubview:self.xieCompanyLab];
        
        self.line2 = [UILabel new];
        self.line2.backgroundColor = Color_backgroundColor;
        [self.bgView addSubview:self.line2];
        
        self.linkLine = [UILabel new];
        self.linkLine.backgroundColor = HexColorA(0x3D68EB, 0.2);
        [self.bgView addSubview:self.linkLine];
        
        self.listBtn = [UIButton new];
        [self.listBtn setTitle:@"货物清单" forState:0];
        [self.listBtn setTitleColor:Color_ThemeColor forState:0];
        self.listBtn.titleLabel.font = BoldFontOfSize(16);
        self.listBtn.backgroundColor = HexColorA(0x3D68EB, 0.1);
        self.listBtn.layer.masksToBounds = YES;
        [self.listBtn addTarget:self action:@selector(listClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.listBtn];
        
    }
    return self;
}

- (void)listClick {
    if (self.listBlock) {
        self.listBlock();
    }
}

-(void)setModel:(TiDanDetailPlanModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 10;
    self.bgView.nim_width = ScreenW - 30;
    
    self.NOTitleLab.text = @"提货单号：";
    [self.NOTitleLab sizeToFit];
    self.NOTitleLab.nim_left = 15;
    self.NOTitleLab.nim_top = 15;
    
    self.NOLab.text = self.model.serial_num;
    [self.NOLab sizeToFit];
    self.NOLab.nim_left = self.bgView.nim_width - 15 - self.NOLab.nim_width;
    self.NOLab.nim_centerY = self.NOTitleLab.nim_centerY;
    
    self.line1.frame = CGRectMake(0, self.NOTitleLab.nim_bottom + 15, self.bgView.nim_width, 2);
    
    self.tiNameLab.text = self.model.delivery_liaison;
    [self.tiNameLab sizeToFit];
    self.tiNameLab.nim_left = 60;
    self.tiNameLab.nim_top = self.line1.nim_bottom + 15;
    
    self.tiAddressLab.text = self.model.delivery_address;
    self.tiAddressLab.nim_width = self.bgView.nim_width - 15 - self.tiNameLab.nim_left;
    [self.tiAddressLab sizeToFit];
    self.tiAddressLab.nim_left = self.tiNameLab.nim_left;
    self.tiAddressLab.nim_top = self.tiNameLab.nim_bottom + 5;
    
    self.tiCompanyLab.text = self.model.delivery_name;
    self.tiCompanyLab.nim_width = self.bgView.nim_width - 15 - self.tiNameLab.nim_left;
    [self.tiCompanyLab sizeToFit];
    self.tiCompanyLab.nim_left = self.tiNameLab.nim_left;
    self.tiCompanyLab.nim_top = self.tiAddressLab.nim_bottom + 5;
    
    self.marginLine.frame = CGRectMake(52, self.tiCompanyLab.nim_bottom + 10, self.bgView.nim_width - 52, 1);
    
    self.xieNameLab.text = self.model.unload_liaison;
    [self.xieNameLab sizeToFit];
    self.xieNameLab.nim_left = 60;
    self.xieNameLab.nim_top = self.marginLine.nim_bottom + 10;
    
    self.xiePhoneLab.text = self.model.unload_tel;
    [self.xiePhoneLab sizeToFit];
    self.xiePhoneLab.nim_left = self.xieNameLab.nim_right + 8;
    self.xiePhoneLab.nim_centerY = self.xieNameLab.nim_centerY;
    
    self.xieAddressLab.text = self.model.unload_address;
    self.xieAddressLab.nim_width = self.bgView.nim_width - 15 - self.tiNameLab.nim_left;
    [self.xieAddressLab sizeToFit];
    self.xieAddressLab.nim_left = self.tiNameLab.nim_left;
    self.xieAddressLab.nim_top = self.xieNameLab.nim_bottom + 5;
    
    self.xieCompanyLab.text = self.model.unload_name;
    self.xieCompanyLab.nim_width = self.bgView.nim_width - 15 - self.tiNameLab.nim_left;
    [self.xieCompanyLab sizeToFit];
    self.xieCompanyLab.nim_left = self.tiNameLab.nim_left;
    self.xieCompanyLab.nim_top = self.xieAddressLab.nim_bottom + 5;
    
    self.line2.frame = CGRectMake(0, self.xieCompanyLab.nim_bottom + 15, self.bgView.nim_width, 2);
    
    self.tiImgView.nim_width = 22;
    self.tiImgView.nim_height = 22;
    self.tiImgView.nim_left = 20;
    self.tiImgView.nim_top = (self.marginLine.nim_top - self.line1.nim_bottom - self.tiImgView.nim_width) * 0.5 + self.line1.nim_bottom;
    
    self.xieImgView.nim_width = 22;
    self.xieImgView.nim_height = 22;
    self.xieImgView.nim_left = self.tiImgView.nim_left;
    self.xieImgView.nim_top = (self.line2.nim_top - self.marginLine.nim_bottom - self.xieImgView.nim_height) * 0.5 + self.marginLine.nim_bottom;
    
    self.linkLine.nim_top = self.tiImgView.nim_bottom + 3;
    self.linkLine.nim_width = 2;
    self.linkLine.nim_height = self.xieImgView.nim_top - 3 - self.tiImgView.nim_bottom - 3;
    self.linkLine.nim_centerX = self.tiImgView.nim_centerX;
    
    self.listBtn.frame = CGRectMake(15, self.line2.nim_bottom + 10, self.bgView.nim_width - 30, 44);
    self.listBtn.layer.cornerRadius = 6;
    
    self.bgView.nim_height = self.listBtn.nim_bottom + 10;
    
    self.bgView.layer.cornerRadius = 6;
    self.height = self.bgView.nim_bottom + 10;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
